<?php 
include_once "getAccounts.php";
include_once "getAccount.php";
include_once "showEmployeeInfo.php";
include_once "modifyEmployee.php";
include_once "deleteAccount.php";

//save employee modifications
if (isset($_GET['action']))
{
	switch ($_GET['action'])
	{
		case "Save Changes":
			$modifyEmployeeResult = modifyEmployee($userName, $userPassHash,
			$_GET['accName'], $_SESSION[$_GET['accName'] . 'employee'], $_GET['empFname'],
			$_GET['empLname'], $_GET['startDate'], $_GET['endDate'],
			$_GET['empStatus'], $_GET['address'], $_GET['email'],
			$_GET['phoneNum'], $_GET['wage']);
			// 			echo $modifyEmployeeResult;
			break;
		case "Delete Account":
			$deleteAccountResult = deleteAccount($_GET['accName'],
			$userName, $userPassHash, $_SESSION[$_GET['accName'] . 'account']);
			// 			print_r($deleteAccountResult[0]);
			break;
	}
}

//implement bootstrap
echo '<script type="text/javascript" src="js/bootstrap.js"></script>
		<link href="css/bootstrap.css" rel="stylesheet">';

$getAccountsResult = getAccounts($userName, $userPassHash);
$accounts = null;
//grab the accounts
$accounts = $getAccountsResult['results'];
//parse the accounts
foreach ($accounts as &$accountsEntry) {
	$accName=$accountsEntry['accName'];

	$getAccountResult = getAccount($accName, $userName, $userPassHash);
	$_SESSION[$accName . 'account'] = $getAccountResult['results']['dataHash'];
	getAccountInfo($accName);
}


function getAccountInfo($accName){
	$account = showEmployeeInfo($_SESSION['userName'], $_SESSION['userPassHash'], $accName);
	$_SESSION[$accName . 'employee'] = $account['hash'];
	echo
	'<div class="accordion" id="employees">'
			;
			echo
			'<div class="accordion-group">'.
			'<div class="accordion-heading">'.
			'<a class="accordion-toggle" data-toggle="collapse"'.
			'data-parent="#employees" href="#' . $accName . '">' .
			$accName .
			'</a>'.
			'</div>'.
			'<div id="' . $accName . '" class="accordion-body collapse">'.
			'<div class="accordion-inner">' .
			'<form action="template.php">'.
			'<table>'.
			'<tr>'.
			'<td>Account Name</td>'.
			'<td><input type="text" name="accName" value="' . $accName . '" /></td>'.
			'</tr>'.
			generateProfileGroup('First Name', 'empFname', $account).
			generateProfileGroup('Last Name', 'empLname', $account).
			generateProfileGroup('Start Date', 'startDate', $account).
			generateProfileGroup('End Date', 'endDate', $account).
			generateProfileGroup('Status', 'empStatus', $account).
			generateProfileGroup('Address', 'address', $account).
			generateProfileGroup('Email', 'email', $account).
			generateProfileGroup('Phone Number', 'phoneNum', $account).
			generateProfileGroup('Wage', 'wage', $account).
			'<tr><td><input type="submit" name="action" value="Save Changes" /></td>'.
			'<td><input type="submit" name="action" value="Delete Account" /></td></tr>'.
			'</table>'.
			'</form>'.
			'</div>'.
			'</div>'.
			'</div>'
					;
					echo '</div>';
}

function generateProfileGroup($label, $entry, $account)
{
	return
	'<tr>'.
	'<td>' . $label . '</td>'.
	'<td><input type="text" name="'. $entry .'" value="' . $account[$entry] . '" /></td>'.
	'</tr>'
			;
}
?>
